﻿using Mapster;
using SmartAgricultureService.Models.Enums;
using SmartAgricultureService.Tables;

namespace SmartAgricultureService.Models.Tables
{
    public class DeviceInfo
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public string AreaId { get; set; }
        public string CropId { get; set; }
        public string AreaName { get; set; }
        public string CropName { get; set; }
        public string AreaCode { get; set; }
        public DeviceType Type { get; set; }
        public bool Active { get; set; }
        public bool Delete { get; set; }
        public string Mac { get; set; }
        public static TypeAdapterConfig GetAdapterConfig()
        {
            return new TypeAdapterConfig().NewConfig<DeviceEntry, DeviceInfo>()
                .Map(dest => dest.Id, src => src.Id)
                .Map(dest => dest.Name, src => src.Name)
                .Map(dest => dest.Mac, src => src.Mac)
                .Map(dest => dest.Type, src => src.Type)
                .Map(dest => dest.Delete, src => src.Delete)
                .Map(dest => dest.Active, src => src.Active)
                .Map(dest => dest.CropId, src => src.CropId)
                .Map(dest => dest.AreaId, src => src.AreaId)
                .Map(dest => dest.AreaCode, src => src.Area != null ? src.Area.Code : string.Empty)
                .Map(dest => dest.CropName, src => src.Crop != null ? src.Crop.Name : string.Empty)
                .Map(dest => dest.AreaName, src => src.Area != null ? src.Area.Name : string.Empty)
                .Config;
        }
    }
}